<!DOCTYPE html>
<html>
<head>
<title>req_assign</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<link rel="stylesheet" type="text/css"
	href="/codebase/fonts/font_roboto/roboto.css" />
<link rel="stylesheet" type="text/css" href="/codebase/dhtmlx.css" />
<script type="text/javascript" src="/codebase/dhtmlxform.js" />
<script type="text/javascript" src="/codebase/dhtmlxgrid.js" />

<!-- <script type="text/javascript" src="/codebase/dhtmlx.js" ></script> -->

<script>
/*<![CDATA[*/
	var myGrid;
	var myForm, formData;
function doOnLoad() {
		var v=document.getElementById("assign_req_id").innerHTML;
		if (myForm) {
			myForm.unload();
			myForm = null;
		}
		myForm = new dhtmlXForm("myForm");
		//myForm.loadStruct("/common/testmanager/req_modify_detail_base_info.xml");
		myForm.loadStruct("/req/req_modify_detail_team_info_onload?req_id="+v);
		
		myForm.attachEvent("onButtonClick",function(name){
			/* if (name == "add1" || name == "remove1") {
				change_req_head(name=="add1");
			}; */
			 if (name == "add2" || name == "remove2") {
				change_req_analyst(name=="add2");
			};	 
			if (name == "add3" || name == "remove3") {
				change_req_supervisor(name=="add3");
			};	
			if (name == "team_info_save_btn") {		
				var s2=myForm.getSelect("req_analyst");
				 for (var i=0;i<s2.options.length;i++)
				{
					s2.options[i].selected=true
				}			 
				var s3=myForm.getSelect("req_supervisor");
				if(s3!=null){
					for (var i=0;i<s3.options.length;i++)
					{
						s3.options[i].selected=true
					}	
				}				
				myForm.send("/req/req_modify_detail_team_info_save",callback);
				
			}
			
		});
		

		//grid setup
		if (myGrid) {
			myGrid.clearAll(true);
		}
		myGrid = new dhtmlXGridObject("grid_team_list");
		//myGrid.loadStruct("/common/testmanager/req_list.xml");
		myGrid.setImagePath("/codebase/imgs/");

		myGrid.setHeader("日期,姓名,调入/调出,备注");
		myGrid.setInitWidths("150,200,100,200");
		myGrid.setColAlign("left,left,left,left");
		myGrid.setColTypes("ro,ro,ro,ro");
		myGrid.setColSorting("str,str,str,str");
		//myGrid.setColumnIds("first,second");
		myGrid.xml.top = "mytop";
		myGrid.xml.row = "./myrow";

		myGrid.init();
		myGrid.clearAndLoad("/req/req_modify_detail_team_info_grid?req_id=" + v,"json");
		//myGrid.load("/common/testmanager/req_modify_detail_team_info_test_data.xml","xml");
		/*
		var myCombo = new dhtmlXCombo("combo_zone","alfa3",200,"checkbox");
		myCombo.addOption([
		 {value:"a", text:"option A", img_src:"../images/blue.gif", css:"color:red;"}, 
		 {value:"b", text:"option B", img_src:"../images/green.gif"}, 
		 {value:"c", text:"option C", img_src:"../images/red.gif"}
		]);
		myCombo.enableFilteringMode(true);
		*/	
	}


function change_req_head(block) {
	
	var ida = (block?"req_head":"req_head_all");
	var idb = (block?"req_head_all":"req_head");
	
	var sa = myForm.getSelect(ida);
	var sb = myForm.getSelect(idb);
	
	var t = myForm.getItemValue(ida);
	if (t.length == 0) return;
	eval("var k={"+t.join(":true,")+":true};");
	
	var w = 0;
	var ind = -1;
	while (w < sa.options.length) {
		if (k[sa.options[w].value]) {
			sb.options.add(new Option(sa.options[w].text,sa.options[w].value));
			sa.options.remove(w);
			ind = w;
		} else {
			w++;
		}
	}
	
	if (sa.options.length > 0 && ind >= 0) {
		if (sa.options.length > 0) sa.options[t.length>1?0:Math.min(ind,sa.options.length-1)].selected = true;
	}
	
}

function change_req_analyst(block) {
	
	var ida = (block?"req_analyst":"req_analyst_all");
	var idb = (block?"req_analyst_all":"req_analyst");
	
	var sa = myForm.getSelect(ida);
	var sb = myForm.getSelect(idb);
	
	var t = myForm.getItemValue(ida);
	if (t.length == 0) return;
	eval("var k={"+t.join(":true,")+":true};");
	
	var w = 0;
	var ind = -1;
	while (w < sa.options.length) {
		if (k[sa.options[w].value]) {
			sb.options.add(new Option(sa.options[w].text,sa.options[w].value));
			sa.options.remove(w);
			ind = w;
		} else {
			w++;
		}
	}
	
	if (sa.options.length > 0 && ind >= 0) {
		if (sa.options.length > 0) sa.options[t.length>1?0:Math.min(ind,sa.options.length-1)].selected = true;
	}
	
}

function change_req_supervisor(block) {
	
	var ida = (block?"req_supervisor":"req_supervisor_all");
	var idb = (block?"req_supervisor_all":"req_supervisor");
	
	var sa = myForm.getSelect(ida);
	var sb = myForm.getSelect(idb);
	
	var t = myForm.getItemValue(ida);
	if (t.length == 0) return;
	eval("var k={"+t.join(":true,")+":true};");
	
	var w = 0;
	var ind = -1;
	while (w < sa.options.length) {
		if (k[sa.options[w].value]) {
			sb.options.add(new Option(sa.options[w].text,sa.options[w].value));
			sa.options.remove(w);
			ind = w;
		} else {
			w++;
		}
	}
	
	if (sa.options.length > 0 && ind >= 0) {
		if (sa.options.length > 0) sa.options[t.length>1?0:Math.min(ind,sa.options.length-1)].selected = true;
	}
	
}

var callback=function () {
	//alert("callback");
	
	if(arguments[1]=="true"){
		alert("保存修改成功");	
		var v=document.getElementById("assign_req_id").innerHTML;
		myGrid.clearAndLoad("/req/req_modify_detail_team_info_grid?req_id=" + v,"json");
	}
	else{
		alert("保存修改失败，错误信息："+arguments[1]);
	}
}
/*]]>*/

</script>
</head>
<body onload="doOnLoad();">
<div id="assign_req_id" name="assign_req_id" th:text="${req_id}" style="display: none;" > </div>
<div id="combo_zone"></div>
	<table>
			<tr>
			<td>
				<div id="myForm" style="width: 800px;"></div>
				</td>
		</tr>
		<tr>
			<td>
				<div id="form_req_base_info"></div>
			</td>
		</tr>

	</table>
	<table>
		<tr>
			<td>
				<div id="grid_team_list"
					style="width: 800px; height: 200px; background-color: white;">
				</div>
			</td>
		</tr>
	</table>
</body>
</html>